package cn.xiaomubiao.oschine.adapter.news_adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseRecyclerViewAdapter;
import cn.xiaomubiao.oschine.bean.Blog;
import cn.xiaomubiao.oschine.util.UIUtils;

/**
 * 博客/推荐 列表适配器
 *
 * @author 余伟舟
 */

public class BlogsAdapter extends BaseRecyclerViewAdapter {

//    MyItemClickListener mItemClickListener;
    List<Blog> mStringList = new ArrayList<>();

    public BlogsAdapter(List<Blog> stringList) {
        mStringList = stringList;

    }

    @Override
    public ViewHoders onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(UIUtils.getContext(), R.layout.news_adapter_title, null);
        ViewHoders hoders=new ViewHoders(view); //mItemClickListener
        return hoders;
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        ViewHoders hoders= (ViewHoders) holder;
        Blog blog = mStringList.get(position);

        hoders.mTitle.setText(blog.getTitle());
        hoders.mContent.setText(blog.getBody());
        hoders.mName.setText(blog.getAuthor());
        hoders.mViewById.setText(blog.getPubDate());
        hoders.mId.setText(blog.getCommentCount()+"");
    }

    @Override
    public int getItemCount() {
        return mStringList.size();
    }

    /*//全局监听接口
    public interface MyItemClickListener {
        void onItemClick(View view, int position);
    }

    //对外提供调用方法,实现item监听
    public void setItemClickListener(MyItemClickListener myItemClickListener) {
        this.mItemClickListener = myItemClickListener;
    }*/


    public class ViewHoders extends RecyclerView.ViewHolder {//implements View.OnClickListener

       // private MyItemClickListener mListener;
        private  TextView mTitle;
        private  TextView mContent;
        private  TextView mName;
        private  TextView mViewById;
        private  TextView mId;

        //将全局的监听赋值给接口
        public ViewHoders(View itemView) { //, MyItemClickListener myItemClickListener
            super(itemView);
            mTitle = (TextView) itemView.findViewById(R.id.title);
            mContent = (TextView) itemView.findViewById(R.id.content);
            mName = (TextView) itemView.findViewById(R.id.name);
            mViewById = (TextView) itemView.findViewById(R.id.time);
            mId = (TextView) itemView.findViewById(R.id.siez);

//            this.mListener = myItemClickListener;
//            itemView.setOnClickListener(this);
        }

//        //实现click重写方法
//        @Override
//        public void onClick(View view) {
//            if (mListener != null) {
//                mListener.onItemClick(view,getPosition());
//            }
//        }
    }
}
